package com.huluobo.a2109kotlinshopping.mine

import android.content.Intent
import android.util.Log
import com.blankj.utilcode.util.SPUtils
import com.huluobo.a2109kotlinshopping.R
import com.huluobo.a2109kotlinshopping.base.BaseMVVMFragment
import com.huluobo.a2109kotlinshopping.databinding.FragmentMineBinding
import com.huluobo.a2109kotlinshopping.db.DatabaseUtil
import com.huluobo.a2109kotlinshopping.login.LoginActivity
import com.huluobo.a2109kotlinshopping.login.UserBean
import com.huluobo.a2109kotlinshopping.net.Const
import com.huluobo.a2109kotlinshopping.order.OrderPayActivity
import com.huluobo.a2109kotlinshopping.setting.SettingActivity
import com.huluobo.a2109kotlinshopping.utils.ImageUtils


class MineFragment : BaseMVVMFragment<FragmentMineBinding>() {
    override fun getLayoutId(): Int = R.layout.fragment_mine
    lateinit var user: UserBean

    override fun initData() {
        val userId = SPUtils.getInstance().getInt(Const.SP_ID, 0)
        user = DatabaseUtil.getDb().userInfoDao().queryUserInfo(userId)
        //用户头像
        ImageUtils.loadImage(requireContext(), user.icon, dataBinding.mineIvUserIcon)
        //用户名
        dataBinding.mineNickName.text = user.nickname
    }

    override fun initView() {
        dataBinding.mineTvLogout.setOnClickListener {
            val intent = Intent(requireContext(), LoginActivity::class.java)
            startActivity(intent)
            requireActivity().finish()
        }

        dataBinding.mineClOrders.setOnClickListener {
            val intent = Intent(requireContext(), OrderPayActivity::class.java)
            startActivity(intent)
        }

        dataBinding.mineClAddress.setOnClickListener {
            val intent = Intent(requireContext(), AddressActivity::class.java)
            startActivity(intent)
        }

        dataBinding.mineClSettings.setOnClickListener {
            val intent = Intent(requireContext(), SettingActivity::class.java)
            startActivity(intent)
        }
    }
}